package com.soft.javase.ch06.calendar;

import java.util.Calendar;


/**
 * @author wangzhisen
 * @Desc TODO
 * @date 2025/4/27
 */
public class CalendarDemo {
    public static void main(String[] args) {
        //获得日历对象
        Calendar c = Calendar.getInstance();

        //追加
        addCalendar(c);

        //设置
        setCalendar(c);

        //获取
        getCalendar(c);

    }
    //获取年、月、日、时、分、秒、星期
    public static void getCalendar(Calendar c){
        //日期
        System.out.println("year = "+c.get(Calendar.YEAR));
        System.out.println("month = "+(c.get(Calendar.MONTH)+1));
        System.out.println("date = "+c.get(Calendar.DATE));

        //时间
        System.out.println("hour = "+c.get(Calendar.HOUR));
        System.out.println("minute = "+c.get(Calendar.MINUTE));
        System.out.println("second = "+c.get(Calendar.SECOND));

        //星期
        System.out.println("week = "+getWeek(c.get(Calendar.DAY_OF_WEEK)));
    }

    //设置年、月、日、时、分、秒
    public static void setCalendar(Calendar c){
        //设置 第一个参数：设置的单位  第二个参数：设置的值
        c.set(Calendar.YEAR, 2023);
    }

    //追加
    public static void addCalendar(Calendar c){
        //追加 第一个参数：追加的单位  第二个参数：数值
        c.add(Calendar.MONTH, 2);
    }

    public static String getWeek(int i){
        String[] weeks={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
        return weeks[i-1];
    }
}
